package com.edu.study.base.commonController;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.edu.common.systemSetup.domain.SystemSetup;
import com.edu.common.systemSetup.service.ISystemSetupService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.utils.uuid.IdUtils;

/**
 * 系统设置Controller
 * 
 * @author zw
 * @date 2021-02-19
 */
@RestController
@RequestMapping("/systemSetup")
public class SystemSetupController extends BaseController
{
    @Autowired
    private ISystemSetupService systemSetupService;

    /**
     * 查询系统设置列表
     */
    @PreAuthorize("@ss.hasPermi('systemSetup:systemSetup:list')")
    @GetMapping("/list")
    public TableDataInfo list(SystemSetup systemSetup)
    {
        startPage();
        List<SystemSetup> list = systemSetupService.selectSystemSetupList(systemSetup);
        return getDataTable(list);
    }

    /**
     * 导出系统设置列表
     */
    @PreAuthorize("@ss.hasPermi('systemSetup:systemSetup:export')")
    @Log(title = "系统设置", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(SystemSetup systemSetup)
    {
        List<SystemSetup> list = systemSetupService.selectSystemSetupList(systemSetup);
        ExcelUtil<SystemSetup> util = new ExcelUtil<SystemSetup>(SystemSetup.class);
        return util.exportExcel(list, "systemSetup");
    }

    /**
     * 获取系统设置详细信息
     */
    @PreAuthorize("@ss.hasPermi('systemSetup:systemSetup:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(systemSetupService.selectSystemSetupById(id));
    }

    /**
     * 新增系统设置
     */
    @PreAuthorize("@ss.hasPermi('systemSetup:systemSetup:add')")
    @Log(title = "系统设置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SystemSetup systemSetup)
    {
        systemSetup.setId(IdUtils.simpleUUID());
        systemSetup.setCreateBy(SecurityUtils.getUsername());
        systemSetup.setCreateDate(new Date());
        return toAjax(systemSetupService.insertSystemSetup(systemSetup));
    }

    /**
     * 修改系统设置
     */
    @PreAuthorize("@ss.hasPermi('systemSetup:systemSetup:edit')")
    @Log(title = "系统设置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SystemSetup systemSetup)
    {
        return toAjax(systemSetupService.updateSystemSetup(systemSetup));
    }

    /**
     * 删除系统设置
     */
    @PreAuthorize("@ss.hasPermi('systemSetup:systemSetup:remove')")
    @Log(title = "系统设置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(systemSetupService.deleteSystemSetupByIds(ids));
    }
}
